<?php
// prefix use sub
$subLockFile = DT_CACHE . '/subscribe/subscribe.lock';
if (!file_exists($subLockFile)) {
	File::dirCreate(dirname($subLockFile));
	touch($subLockFile);
}
// perhour to refresh
// 26.php 为资讯
if (($DT_TIME - filemtime($subLockFile) > 3600) || !file_exists(DT_CACHE . '/subscribe/quote.php')) {
	//		do update
	$subTables = array(
		6=> 'buy',
		21=>'traffic',
		26=>'information',
		5=>'sell',
		7=>'purchase',
		11=>'cooperation',
		24=>'quote',
		23=>'guide',
	);
	foreach ($subTables as $k => $table) {
		$subTable = $db->getPre() . $table;
		$options  = array(
			'limit'      => 10,
			'where' => 'status=3',
			'order'      => 'edittime desc',
		);
		$sqb = new SQLBuilder($subTable);
		$sql = $sqb->buildSelect($options);
		$tmp      = $db->getAll($sql);
		foreach($tmp as $ck => $v) {
			if ($table=='infomation'){
				$m = 'info';
			} else {
				$m = $table;
			}

			$v['linkurl'] = url($m.'/show', 'itemid='.$v['itemid']);
			$tmp[$ck] = $v;
		}
		PCache::write($k . '.php', $tmp, 'subscribe');
	}
}
